package com.clouddisk.common.core.domain.entity;

import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.clouddisk.common.utils.FilesUtils;
import com.qiwenshare.common.util.DateUtil;

import lombok.Data;


@Data

@TableName("userfile")
public class UserFile {
    @TableId(value = "user_file_id")
    private String userFileId;

    /**
     * 用户id
     */
    private Long userId;

    /**
     * 文件id
     */
    private String fileId;

    /**
     * 文件名
     */
    private String fileName;

    /**
     * 文件所属部门
     */
    public String fileDeptName;

    /**
     * 文件路径
     */
    private String filePath;

    /**
     * 扩展名
     */
    private String extendName;

    /**
     * 是否是目录(0-否,1-是)
     */
    private Integer isDir;

    /**
     * 修改时间
     */
    private String uploadTime;

    /**
     * 删除标识(0-未删除，1-已删除)
     */
    private Integer deleteFlag;

    /**
     * 删除时间
     */
    private String deleteTime;

    /**
     * 删除批次号
     */
    private String deleteBatchNum;

    public UserFile() {};
    public UserFile(FilesUtils filesUtils, long userId, String fileId, String fileDeptName) {
        this.userFileId = IdUtil.getSnowflakeNextIdStr();
        this.userId = userId;
        this.fileId = fileId;
        this.filePath = filesUtils.getParent();
        this.fileName = filesUtils.getNameNotExtend();
        this.extendName = filesUtils.getExtendName();
        this.fileDeptName = fileDeptName;
        this.isDir = filesUtils.isDirectory() ? 1 : 0;
        this.uploadTime = DateUtil.getCurrentTime();
        this.deleteFlag = 0;
    }

    public boolean isDirectory() {
        return this.isDir == 1;
    }

    public boolean isFile() {
        return this.isDir == 0;
    }

}
